<!-- 以下代码为代码生成器生成，生成时间: 2017-07-02 05:13:15，作者：billjiang/475572229@qq.com-->
<section class="content-header">
    <h1>
        委托管理
        <small>列表</small>
    </h1>
    <ol class="breadcrumb">
        <li><a href="${basePath}"><i class="fa fa-dashboard"></i> 首页</a></li>
        <li><a href="#">工作流管理</a></li>
        <li class="active">委托管理</li>
    </ol>
</section>

<section class="content">
    <div class="row">
        <div class="col-xs-12">
            <div class="box">
                <!-- /.box-header -->
                <div class="dataTables_filter" id="searchDiv" style="display: none">
                    <!--查询条件-->
                    <select name="d.MODULE_ID_" id="moduleId" data-src="/activiti/module/getAll" data-flag="urlSelector"
                            data-placeholder="请选择委托业务" class="form-control select2" style="width:140px"
                            data-blank="true" operator="like" likeOption="true"></select>
                    <input class="form-control" type="text" name="ae.name" likeOption="true" operator="like" placeholder="请填写委托人姓名">
                    <div class="input-group">
                        <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
                        <input type="search" placeholder="委托开始时间" title="委托开始时间" name="d.START_TIME_" data-flag="datepicker" class="form-control" data-format="yyyy-mm-dd">
                    </div>
                    ~
                    <div class="input-group">
                        <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
                        <input type="search" placeholder="委托结束时间" title="委托结束时间" name="d.START_TIME_" data-flag="datepicker" class="form-control" data-format="yyyy-mm-dd">
                    </div>
                    <div class="btn-group">
                        <button type="button" class="btn btn-primary" data-btn-type="search">查询</button>
                        <button type="button" class="btn btn-default" data-btn-type="reset">重置</button>
                    </div>
                    <div class="btn-group">
                        <button type="button" class="btn btn-default" data-btn-type="add">新增</button>
                        <button type="button" class="btn btn-default" data-btn-type="edit">编辑</button>
                        <button type="button" class="btn btn-default" data-btn-type="delete">删除</button>
                    </div>
                </div>
                <div class="box-body">
                    <table id="delegate_table" class="table table-bordered table-striped table-hover">
                    </table>
                </div>
            </div>
        </div>
    </div>
</section>

<script>
    var form_list = $("#searchDiv").form({baseEntity: false});
    form_list.initComponent();
    var delegateTable, winId = "delegateWin";

    $(function (){
        delegateTable = new CommonTable("delegate_table", "delegate_list", "searchDiv", null);
        //绑定按钮事件
        $("button[data-btn-type]").click(function () {
            var action = $(this).data("btn-type");
            var rowId = delegateTable.getSelectedRowId();
            switch (action) {
                case "add":
                    modals.openWin({
                        winId: winId,
                        title: '新增委托',
                        width: "800px",
                        url: basePath + "/activiti/delegate/list/edit"
                    })
                    break;
                case "edit":
                    if (!rowId) {
                        modals.info('请选择要编辑的行');
                        return false;
                    }
                    modals.openWin({
                        winId: winId,
                        title: '编辑委托【' + delegateTable.getSelectedRowData().name + '】',
                        width: '800px',
                        url: basePath + "/activiti/delegate/list/edit?id=" + rowId
                    });
                    break;
                case 'delete':
                    if (!rowId) {
                        modals.info('请选择要删除的行');
                        return false;
                    }
                    modals.confirm("是否要删除该行数据？", function () {
                        ajaxPost(basePath + "/activiti/delegate/delete/" + rowId, null, function (data) {
                            if (data.success) {
                                delegateTable.reloadRowData();
                            } else {
                                modals.info(data.message);
                            }
                        });
                    });
                    break;
            }
        })
    })

    function fnRenderDelegateState(value,type,rowObj) {
        if(value==1){
            return "<span class='label label-danger'>禁用</span>"
        }else if(value==0){
            var curTime=new Date(getServerTime(basePath,"yyyy-mm-dd"));
            var startTime=new Date(rowObj.startTime);
            var endTime=new Date(rowObj.endTime);
            if(startTime>curTime){
                return "<span class='label label-danger'>未开始</span>";
            }else if(endTime<curTime){
                return "<span class='label label-danger'>已超时</span>";
            }
            return "<span class='label label-success'>启用</span>";
        }
    }

    function fnRenderOperator(value) {
        return "<a href='javascript:void(0)' onclick='showHistory(\"" + value + "\")'>委托历史</a>";
    }

    function showHistory(delegateId) {
       alert(delegateId);
    }


</script>